<?php

class XMLDocument {
	var $dom;
	
	function XMLDocument($file_name) {
		if (substr_count($file_name, "<?xml")==0) {
			if (file_exists($file_name))
				$this->dom = domxml_open_file($file_name);
		} else {
			$this->dom = domxml_open_mem($file_name);
		}
	}
	
	function getDOM() {
		return $this->dom;
	}
	
	function getBinary($tagName, $id="") {
		$docElements = $this->dom->get_elements_by_tagname($tagName);
		foreach ($docElements as $child) {
			if ($child->type==1 && $child->get_attribute('id')==$imageId) {
				return base64_decode($child->get_content());
			}
		}
	}
	
	function toString() {
		return "XMLDocument: ";
	}
	
	function getContent() {
		if ($this->dom) {
			return $this->dom->dump_mem();
		}
		return "";
	}
	
	function addNodesTo($parent, $newNodes) {
		if ($parent && $newNodes) {
			for ($i = 0; $i < sizeof($newNodes); $i++) {
				$node = $newNodes[$i]->clone_node(true);
        		$parent->append_child($node);
			}
		}
	}
}
?>